<template>
<el-row v-loading="loading">
    <el-col :span="24">
      <physical-ck ref="physicalCk" v-on:save-finished="getPhysicalList()"></physical-ck>
      <el-row class="search-row">
        <el-col :span="5">
          <el-input placeholder="请输入预约人的身份证" size="small" v-model="isCardLike">
          <el-button slot="append" icon="el-icon-search" @click="getPhysicalList(isCardLike)"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-table :data="getPhysicalList(isCardLike).slice((pageNum-1)*pageSize,pageNum*pageSize)" border size="mini" header-cell-class-name="header-row">
            <el-table-column prop="tMember.id" label="编号" header-align="center"></el-table-column>
            <el-table-column prop="tMember.name" label="操作人" header-align="center"></el-table-column>
            <el-table-column prop="tMember.fileNumber" label="档案号" header-align="center"></el-table-column>
            <el-table-column prop="updatetime" label="最后操作时间" header-align="center" align="center"></el-table-column>
            <el-table-column prop="reportStatus" label="报告状态" :formatter="formatreportStatus" header-align="center" align="center"></el-table-column>
            <el-table-column label="操作" header-align="center" align="center" width="200">
              <template slot-scope="scope">
                <el-button v-show="ck" type="text" size="mini"
                  @click="handleCkphysical(scope.row)" v-if="scope.row.reportStatus===1" class="el-icon-zoom-in">查看</el-button>
                  <el-button v-show="tj" type="text" size="mini"
                  @click="handleYTjphysical(scope.row)" v-if="scope.row.reportStatus===0" class="el-icon-s-promotion">体检</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-pagination
            background
            @size-change="handleSizeChange"
            :current-page.sync="pageNum"
            :page-sizes="[5, 10, 20]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="physicalList.length">
          </el-pagination>

      <el-dialog :title="title" :visible.sync="show" width="800px">
      <el-form :model="TMemberExamination" label-width="80px" label-position="right" size="small">
        <div v-show="show2">
        <h2>个人信息</h2><br>
        &emsp;<span>档案号</span>
        &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
        <span>姓名</span><br>
          <input v-model="TMemberExamination.tMember.fileNumber" :disabled="true"/>
        &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
          <input v-model="TMemberExamination.tMember.name" :disabled="true"/>
        <br><br>

        &emsp;<span>身份证</span>
        &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
        <span>出生日期</span><br>
        <input v-model="TMemberExamination.tMember.idCard" :disabled="true"/>
        &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
        <input v-model="TMemberExamination.tMember.birthday" :disabled="true"/>
        <br><br>

        &emsp;<span>邮箱</span>
        &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
        <span>手机号</span><br>
        <input v-model="TMemberExamination.tMember.email" :disabled="true"/>
        &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
        <input v-model="TMemberExamination.tMember.phoneNumber" :disabled="true"/>
        <br><br>
        </div>
        <h3>[{{TMemberExamination.tSetmeal.tname}}]</h3>
        &emsp;<span>检测项目</span>
        &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
        &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
        <span>结果</span>
        <hr><br>
        <el-table :data="jcxmm" border size="mini" header-cell-class-name="header-row">
          <el-table-column prop="tCheckitem.name" header-align="center" align="center"></el-table-column>
          <el-table-column prop="checkitemData" label="" header-align="center" align="center">
            <template slot-scope="scope">
              <p v-if="zt==1">{{scope.row.checkitemData}}</p>
              <input  v-if="zt==0" name="tCheckitemName"/>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <span slot="footer" class="dialog-footer">
      <el-button type="primary" size="small" v-if="zt==1" @click="qr()">打 印</el-button>
      <el-button type="primary" size="small" v-if="zt==0" @click="qr2()">完成报告</el-button>
      <el-button size="small" @click="show=false">取 消</el-button>
    </span>
    </el-dialog>
        </el-col>
      </el-row>
    </el-col>
  </el-row>


</template>

<script>
import {PhysicalQueryAll,PhysicalQueryByid} from '@/api/Physical_examination_upload_tj'
import {queryById,wcbg} from '@/api/tjbg'
import PhysicalCk from '@/components/physical/physicalCk'
export default {
  data() {
    return {
      loading:false,
      physicalList:[],
      pageSize:5,//每页显示的条数
      pageNum:1,
      ck:true,
      tj:true,
      isCardLike:"",
      zt:0,
      tjid:"",
      show:false,
      show2:false,
      title:'体检报告表',
      jcxcd:"",
      jg:{},
      tjid:'',
      ckfw:[],
      jcxmm:[],
      jcxmm2:[],
      TMemberExamination:{
        tMember:{
        },
        tSetmeal:{
        },
        tCheckitem:{
        }
      },
     }
  },
  methods: {
    handleSizeChange(val) {
     this.pageSize = val;
     this.getPhysicalList(isCardLike)
    },
    async pageInit() {
      try {
        let [listPhysicalResp] = await Promise.all([
         PhysicalQueryAll()
        ])
        this.physicalList = listPhysicalResp.data
      } catch(error) {
        this.outputError(error)
      }
    },
    getPhysicalList(isCardLike){
					return this.physicalList.filter((item,i)=>{
							//包含 includes 的意思
							if(item.tMember.idCard.includes(isCardLike)){
								return item;
							}
						})
    },
  async handleCkphysical(row) {
    console.log(row.tMember.id)
      this.tj=row.tMember.id
      this.show=true;
      this.show2=true;
      this.tjid=row.tMember.id
      if(row.portStatus==0){
        this.zt =0;
      }
      if(row.reportStatus==1){
        this.zt =1;
      }
      this.TMemberExamination.tMember=row.tMember;
      this.TMemberExamination.tSetmeal=row.tSetmeal;
      this.TMemberExamination.tCheckitem=row.tCheckitem;
      try{
        let [aaa]=await Promise.all([
          queryById(row.tMember.id)
        ])
        console.log(aaa.data)
        this.jcxmm=aaa.data;
      }catch(error){
        console.log(error)
      }

    },
    formatreportStatus:function (row, column, cellValue) {
            if (cellValue===1){
                return '体检已完成';
            }else if (cellValue===0){
                return '体检未完成';
            }
        },
     async handleYTjphysical(row){
      console.log(row.tMember.id)
      this.show=true;
      this.show2=false;
      this.tjid=row.tMember.id;
      if(row.reportStatus==0){
        this.zt =0;
      }
      if(row.reportStatus==1){
        this.zt =1;
      }
      this.TMemberExamination.tSetmeal=row.tSetmeal;
      console.log(this.TMemberExamination.tSetmeal)
      try{
        let [aaa]=await Promise.all([
          queryById(row.tMember.id)
        ])
        this.jcxmm=aaa.data;
      }catch(error){
        console.log(error)
      }
    },
    async qr2(){
      var chek=new Array();
      var km=document.getElementsByName("tCheckitemName");
      for (var i=0;i<km.length;i++){
        chek.push({tMemberId:this.tjid,checkitemName:this.jcxmm[i].checkitemName,checkitemData:km[i].value,tSetmealId:this.TMemberExamination.tSetmeal.tid})
      }
      console.log(JSON.stringify(chek))
        try{
          let [aaa]=await Promise.all([
            wcbg(JSON.stringify(chek))
          ])
          console.log(aaa.data)
          this.show=false;
          this.pageInit();
        }catch(error){
          console.log(error)
        }
      }
  },
  components:{PhysicalCk},
  created() {
      this.pageInit();
    }

}
</script>

<style>

</style>
